package com.yanqu.road.server.manager.tomb.timer;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.server.manager.tomb.TombActivity;
import com.yanqu.road.server.manager.tomb.TombMaze;
import com.yanqu.road.server.manager.tomb.TombServiceMgr;
import com.yanqu.road.utils.executor.GeneralTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Map;

public class TombPathMergeTask extends GeneralTask {
    private static Logger logger = LogManager.getLogger(TombPathMergeTask.class.getName());

    @Override
    public void doRun() {
        for (TombActivity tombActivity : TombServiceMgr.getActivityMap().values()) {

            boolean isShowTime = false;
            ActivityInfo activityInfo = tombActivity.getActivityInfo();
            long nowSecondTimestamp = System.currentTimeMillis() / 1000;

            if (nowSecondTimestamp > activityInfo.getEndShowTime()) {
                TombServiceMgr.getActivityMap().remove(activityInfo.getActivityId());
                continue;
            }

            if (nowSecondTimestamp > activityInfo.getBeginShowTime()) {
                isShowTime = true;
            }
            if (!isShowTime) {
                continue;
            }

            for (Map.Entry<Integer, Map<Integer, TombMaze>> entry : tombActivity.getTombMazeMap().entrySet()) {
                Map<Integer, TombMaze> tombMazeMap = entry.getValue();
                for (TombMaze tombMaze : tombMazeMap.values()) {
                    if (tombMaze.getDbTombMaze().getFirstIntoUserId() == 0) {
                        continue;
                    }
                    tombMaze.pathMerge();
                }
            }

        }
    }
}
